package cn.yunxiang.summer.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import cn.yunxiang.summer.common.domain.R;
import cn.yunxiang.summer.common.log.annotation.Log;
import cn.yunxiang.summer.common.log.enums.BusinessType;
import cn.yunxiang.summer.system.domain.SysVersion;
import cn.yunxiang.summer.system.domain.bo.SysVersionBo;
import cn.yunxiang.summer.system.domain.vo.SysVersionVo;
import cn.yunxiang.summer.system.service.ISysVerisonService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fxh
 */
@Tag(name = "app版本管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/version")
public class SysVersionController {

    private final ISysVerisonService sysVerisonService;



    @Operation(summary = "查询app版本管理")
    @PostMapping("/list")
    public R<IPage<SysVersionVo>> list(@RequestBody SysVersionBo query, Page<SysVersion> page){
        return R.ok(sysVerisonService.getList(page,query));
    }

    @Operation(summary = "新增版本")
    @Log(title = "版本管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody SysVersion sysVersion) {
        if (!sysVerisonService.add(sysVersion)) {
            return R.fail("新增版本失败");
        }
        return R.ok("新增成功");
    }

    @Operation(summary = "修改状态")
    @Log(title = "修改状态", businessType = BusinessType.UPDATE)
    @GetMapping("/update")
    public R updateStatus( @RequestParam Long id,
                      @RequestParam Integer status) {
        return R.ok(sysVerisonService.updateStatus(id,status));
    }

    @Operation(summary = "删除版本管理")
    @Log(title = "删除版本管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        return R.ok(sysVerisonService.removeById(id));
    }


}
